﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using System.Windows.Threading;
using System.Text.RegularExpressions;
using Microsoft.Web.Media.SmoothStreaming;
using TED.ViewModels;
using TED.Model;

namespace TED
{
    public partial class Video : PhoneApplicationPage
    {
        private VideoViewModel vvm;
        String url = "david_mccandless_the_beauty_of_data_visualization.html";
        /*
        DispatcherTimer currentPosition = new DispatcherTimer();
        
        String videoUrl;
        
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            this.url = NavigationContext.QueryString["url"];
        }
        */
        
        public Video()
        {
            InitializeComponent();
            vvm = new VideoViewModel();
            this.DataContext = vvm ;
            this.PlayList.ItemsSource = vvm.SilverlightVideoList;
            
        }

        private void RemoveFromPlaylist_Click(object sender, RoutedEventArgs e)
        {
            ListBoxItem selectedListBoxItem = this.PlayList.ItemContainerGenerator.ContainerFromItem
                ((sender as MenuItem).DataContext) as ListBoxItem;

            if (selectedListBoxItem == null)
            {
                return;
            }

            string viewUrl = ((TEDVideo)selectedListBoxItem.Content).ViewUrl.ToString();
            vvm.RemoveVideoFromPlaylist(viewUrl);

            // Update the UI
            this.PlayList.ItemsSource = null;
            this.PlayList.ItemsSource = vvm.SilverlightVideoList;
        }

        private void RemoveAllFromPlaylist_Click(object sender, RoutedEventArgs e)
        {
            vvm.RemoveAllVideosFromPlaylist();
        }
    }
}